package com.jet.sms.remote.member;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultCode;
import com.jet.core.result.ResultJson;
import com.jet.sms.remote.member.vo.MemberInfoVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author dcl
 * @since 2025/2/21 18:21
 */
@Component
public class MemberRemoteFallback implements FallbackFactory<MemberRemoteFeign> {
    @Override
    public MemberRemoteFeign create(Throwable cause) {
        return new MemberRemoteFeign() {

            @Override
            public ResultJson<List<MemberInfoVo>> getListByMemberIds(long merchantNo, List<String> memberIds) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }
        };
    }
}
